package com.ifudata.dvp.app.service.atom.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import org.springframework.stereotype.Component;

import com.ifudata.dvp.app.dao.factory.MapperFactory;
import com.ifudata.dvp.app.dao.mapper.base.bo.AppCollect;
import com.ifudata.dvp.app.dao.mapper.base.bo.AppCollectCriteria;
import com.ifudata.dvp.app.service.atom.interfaces.IAppCollectAtomSV;
import com.ifudata.dvp.sdk.util.DateUtil;

/**
 * 
 * @description
 * @author yuhuan 2018年10月24日
 * @Modifier
 */
@Component
public class AppCollectAtomSVImpl implements IAppCollectAtomSV {

	@Override
	public List<Long> queryAppCollect(Long staffId) {
		List<Long> re = new ArrayList<Long>();
		AppCollectCriteria criteria = new AppCollectCriteria();
		criteria.createCriteria().andUserIdEqualTo(staffId);
		List<AppCollect> list = MapperFactory.getAppCollectMapper().selectByExample(criteria);
		for( AppCollect collect : list ){
			re.add(collect.getMenuId());
		}
		
		return re;
	}

	@Override
	public void coverAppCollect(Long staffId, List<Long> menuIdList) {
		AppCollectCriteria criteria = new AppCollectCriteria();
		criteria.createCriteria().andUserIdEqualTo(staffId);
		MapperFactory.getAppCollectMapper().deleteByExample(criteria);
		
		// 去重
		HashSet<Long> h = new HashSet<Long>(menuIdList);
		menuIdList.clear();
		menuIdList.addAll(h);
		
		AppCollect collect;
		for( Long menuId : menuIdList ){
			collect = new AppCollect();
			collect.setUserId(staffId);
			collect.setMenuId(menuId);
			collect.setCreateTime(DateUtil.getSysDate());
			MapperFactory.getAppCollectMapper().insert(collect);
		}
	}

}
